<?php
/**
 * 
 * @author Freezy
 *
 */
class Dashboard extends MY_Controller {

	function Dashboard(){
		parent::MY_Controller();
		$this->validate_cookie();
	}
	
	function _translate_nav($nav, $userAlias){
		$nv = array();
		foreach ($nav as $title=>$value){
			$nv[$title] = array();
			foreach ($value as $item=>$val){
				$nv[$title][$item] = preg_replace("/(:user)/i",$userAlias, $val);
			}
		}
		return $nv;
	}
	
	function _remap(){
		//validate user first
		$URICount = $this->uri->total_segments();
		$usr = $this->uri->segment(2);	//get username
		$this->_validateUser($usr);
		
		//call function
		$func = $this->uri->segment(4);
		$params = array();
		for($i=5;$i<=$URICount; $i++){
			$params[] = $this->uri->segment($i);
		}
		
	    if ( method_exists($this, $func) ) {
	    	call_user_func_array( array($this, $func), $params);
	    }
	    else if (count($params)<=0){
			$this->index();
		}
	}
	
	function index(){
		$this->load->library('session');
		$usrName = $this->session->userdata('usrname');
		$usrAlias = md5($this->session->userdata('usrname'));

		$this->load->model(array('departemen_model','jabatan_model',
			'karyawan_model','karyawan_history_jabatan_model'));
		$this->load->helper(array('html'));
		$this->load->config('rnd', true);
		$CONF = $this->config->item('rnd');

		$karyData = (array)$this->karyawan_model->select_by_id($usrName)->row();
		
		//layout first
		$layoutConf = $CONF['layout'];
		$layoutConf['left_content'] = array(
			'view'=>'template/horz_nav', 
			'view_data'=>array(
				'data'=>$this->_translate_nav($CONF['nav']['users'],$usrAlias)
			) 
		);
		
		$this->load->model('karyawan_history_jabatan_model');
		$layoutConf['right_content'] = array('view'=>'dashboard_users', 
			'view_data'=>array(
				'limit' => 5,//tampilkan sedikit saja$CONF['search']['limit'],
				'usrAlias'=>$usrAlias,
				'usrName'=>$usrName,
				'nama'=>$karyData['kary_nama'],
				'historyJabatan'=>$this->karyawan_history_jabatan_model->getActive($usrName)
			));
		$this->initialize_layout($layoutConf);
		
		//page
		$pageConf = $CONF['page'];
		$pageConf['jscript_default'][] = 'users/dashboard';
		$pageConf['jscript'] = $pageConf['jscript_default'];
		$pageConf['css'] = $pageConf['css_default'];
		$pageConf['template_view'] = 'template/2_layout';
		$this->initialize_page($pageConf);
		
		$this->finalize_view();
	}
}
/* End of file users/dashboard.php */
/* Location: ./system/application/controllers/users/dashboard.php */